package com.dican.portal.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.dican.portal.login.Conexao;

public class PedidoDAO {
	private static Connection conn;

	public static Integer inserePedido(String query) throws SQLException, Exception
	{
		conn = Conexao.getConnection();
		PreparedStatement stmt = conn.prepareStatement(query);
		Integer row = stmt.executeUpdate();
		stmt.close();
		stmt=null;
		conn.close();
		conn=null;
		return(row);
	}
	
	public static String getNumero(String query) throws SQLException, Exception
	{
		conn = Conexao.getConnection();
		PreparedStatement stmt = conn.prepareStatement(query);
		ResultSet rs = stmt.executeQuery();
		rs.next();
		String numeroPedido = rs.getString("documentno");
		rs.close();
		rs=null;
		stmt.close();
		stmt=null;
		conn.close();
		conn=null;
		return(numeroPedido);
	}
	
	public static String getTransportadoraNome(String transportadoraId) throws SQLException, Exception
	{
		conn = Conexao.getConnection();
		String query = "SELECT NAME FROM M_SHIPPER WHERE M_SHIPPER_ID='"+transportadoraId+"';";
		PreparedStatement stmt = conn.prepareStatement(query);
		ResultSet rs = stmt.executeQuery();
		rs.next();
		String transportadoraNome = rs.getString("NAME");
		rs.close();
		rs=null;
		stmt.close();
		stmt=null;
		conn.close();
		conn=null;
		return(transportadoraNome);
	}
	public static String getCondicaoNome(String condicaoId) throws SQLException, Exception
	{
		conn = Conexao.getConnection();
		String query = "SELECT NAME FROM C_PAYMENTTERM WHERE C_PAYMENTTERM_ID='"+condicaoId+"';";
		PreparedStatement stmt = conn.prepareStatement(query);
		ResultSet rs = stmt.executeQuery();
		rs.next();
		String condicaoNome = rs.getString("NAME");
		rs.close();
		rs=null;
		stmt.close();
		stmt=null;
		conn.close();
		conn=null;
		return(condicaoNome);
	}
}